package com.demo.mybatis_plus.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/*
{
    code: 200, 响应码
    message:"", 响应消息
    data:Object 数据体
}
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponse {

    public static ApiResponse PARAM_ERROR = new ApiResponse(100,"参数验证不通过",null);
    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应消息
     */
    private String message;
    /**
     * 数据体
     */
    private Object data;

    public static ApiResponse success(Object data) {
        return new ApiResponse(200, "success", data);
    }

    public static ApiResponse fail(int code, String message) {
        return new ApiResponse(code, message, null);
    }
}
